package com.uchengwang.ui.cm_ui.me.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.me.bean.FmMeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2018/1/22.
 * 我的界面 对应的点击类别
 */

public class FmMeAdapter extends BaseAdapter{
    private Context context;
    private List<FmMeBean> list = new ArrayList<>();
    public FmMeAdapter(Context context){
        this.context = context;
    }

    public void setData(List<FmMeBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public List<FmMeBean> getData(){
        return list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        FMViewHolder holder = null;
        if (view == null){
            holder = new FMViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.fm_me_layout_item, null);
            holder.me_item_img = view.findViewById(R.id.me_item_img);
            holder.me_item_text = view.findViewById(R.id.me_item_text);
            holder.me_item_msg =  view.findViewById(R.id.me_item_msg);

            view.setTag(holder);
        }else {
            holder = (FMViewHolder) view.getTag();
        }

        FmMeBean bean = list.get(position);
        if (bean.getResId() >0){
            ImageManager.getInstance().loadImage(context, holder.me_item_img, bean.getResId(), ImageManager.ImageType.NARMOL);
        }else {
            holder.me_item_img.setVisibility(View.GONE);
        }
        holder.me_item_text.setText(bean.getName());

        if (bean.isNew()){
            holder.me_item_msg.setVisibility(View.VISIBLE);
        }else {
            holder.me_item_msg.setVisibility(View.GONE);
        }

        return view;
    }

    private class FMViewHolder{
        private ImageView me_item_img,  me_item_msg;
        private TextView me_item_text;
    }
}
